<script setup lang="ts">
import cryptoJs from 'crypto-js';

const md5Encrypt = () => {
  console.log(`cryptoJs: `, cryptoJs.MD5('123').toString());
};
/**
 * 导入Excel
 * @author waldon
 * @date 2023-06-20
 */
const importExcel = async ({ data, file, filename }) => {
  console.log(`data`, data);
  console.log(`file`, file);
  console.log(`filename`, filename);
  console.log(`cryptoJs.lib.WordArray.create(file)`, cryptoJs.lib.WordArray.create(file));
  console.log(
    `cryptoJs.MD5(cryptoJs.lib.WordArray.create(file))`,
    cryptoJs.MD5(cryptoJs.lib.WordArray.create(file)),
  );
  console.log(
    `cryptoJs.MD5(cryptoJs.lib.WordArray.create(file)).toString()`,
    cryptoJs.MD5(cryptoJs.lib.WordArray.create(file)).toString(cryptoJs.enc.Hex),
  );
  console.log(
    `cryptoJs.MD5(cryptoJs.lib.WordArray.create(file)).toString()`,
    cryptoJs.MD5(cryptoJs.lib.WordArray.create(file)).toString(cryptoJs.enc.Hex),
  );
  const reader = new FileReader();
  reader.readAsArrayBuffer(file);
  reader.onload = function () {
    const wordArray = cryptoJs.lib.WordArray.create(reader.result);
    const md5 = cryptoJs.MD5(wordArray).toString();
    console.log(`md5`, md5);
    resolve(md5);
  };
  // const file_md5 = cryptoJs.MD5(cryptoJs.lib.WordArray.create(file)).toString(cryptoJs.enc.Hex);
  // console.log(`file_md5`, file_md5);
};
</script>
<template>
  <div class="crypto-js">
    <div className="page-header">
      <div className="left-part">
        <div className="page-title">加密的使用</div>
      </div>
      <div className="right-part">
        <div className="button-operate"></div>
      </div>
    </div>
    <div class="container-wrapper">
      <a-button type="primary" class="list-btn mr-4" @click="md5Encrypt">md5加密</a-button>
      <a-upload :customRequest="importExcel" :showUploadList="false">
        <a-tooltip placement="top">
          <template #title>导入版号Excel</template>
          <a-button type="primary">导入</a-button>
        </a-tooltip>
      </a-upload>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.crypto-js {
}
</style>
